//
//  SpecificationCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/10/17.
//

import UIKit

class SpecificationCell: UICollectionViewCell {
    var circleImageView: UIImageView!
    var contentLab: UILabel!
    var seaCarFalg: Bool = false
    override init(frame: CGRect){
        super.init(frame: frame)
        self.clipsToBounds = true
        
        self.circleImageView = UIImageView(frame: CGRect(x: 18, y: 0, width: 16, height: 16))
        self.circleImageView.image = UIImage(named: "icon_specification")
        self.contentView.addSubview(self.circleImageView)
        
        self.contentLab = UILabel(frame: CGRect(x: self.circleImageView.right + 3, y: 0, width: (kScreenWidth - 83)/4, height: 35))
        self.contentLab.textColor =  Theme.titleLabColor
        self.contentLab.font = UIFont.init(name: Theme.PingFangSCRegular, size: 14)
        self.contentLab.textAlignment = .left
        self.contentLab.lineBreakMode = .byWordWrapping
        self.contentLab.numberOfLines = 0
        self.contentView.addSubview(self.contentLab)
        
        self.addLayOut()
      
    }
    
    func addLayOut() {
        self.circleImageView.snp.makeConstraints { make in
            make.left.equalTo(14)
            make.centerY.equalTo(self.contentView.snp.centerY)
            make.height.width.equalTo(16)
        }
  
        
        self.contentLab.snp.makeConstraints{ make in
            make.top.equalTo(0)
            make.left.equalTo(self.circleImageView.snp.right).offset(4)
            make.right.equalTo(-5)
            make.height.greaterThanOrEqualTo(35)
            make.bottom.equalTo(0)
        }
    }
    
    func setModel(model: EntitiesModel){
        self.contentLab.text = (model.paramName ?? "") + ": " + (model.value ?? "")
        self.contentLab.sizeToFit()
        let tempH = self.contentLab.frame.size.height
        self.contentLab.snp.updateConstraints { make in
            make.height.greaterThanOrEqualTo(tempH + 10)
        }
        self.updateConstraints()
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
